format PE GUI 4.0 at DefImageBase on '..\include\mx_stub.exe'

include '%fasminc%\win32ax.inc'
;include "..\Include\macros.inc"
include "..\Include\data.inc"
include "..\Include\const.inc"
include "..\Include\struct.inc"

win_color       = 0x666666
x_size          = 400
y_size          = 210
x_coord         = 100
y_coord         = 100

Head_YSize      = 0x16
Head_Color      = 0x80

Resize_XSize    = 10
Resize_YSize    = 10
Resize_offset   = 2

Client_Color    = 0x01F0D0

default_buttons = 10111b

  start:
        mov     [Default_XY],x_coord*65536+y_coord 
        mov     [Default_XYSize],x_size*65536+y_size

        call    Redraw

        mov     ecx,0
        
      Wait_Event:
        call    [WaitMessage]
        cmp     bh,0
        je      Wait_Event

        call    [StdHandler]

        cmp     bh,EventID_Maximize
        jne     no_Maximize
        call    Maximize
        jmp     Wait_Event
      no_Maximize:

        cmp     bh,EventID_Restore
        jne     no_Restore
        call    Restore_
        jmp     Wait_Event
      no_Restore:

        cmp     bh,EventID_Redraw
        jne     no_Redraw
        mov     [Buttons],default_buttons
        mov     [Default_XY],esi
        mov     [Default_XYSize],ebp
        call    Redraw
        jmp     Wait_Event
      no_Redraw:


;        mov     dx,[cnt]
;        shl     edx,16
                 
;        mov     dx,150

;        pusha
;        mov     eax,0x22
;        int     0x90
;        cmp     [old_tick],esi
;        popa
;        ja      no_img

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;      repe_put:
;        mov     esi,PicFile
;        mov     edi,picfile
;        mov     eax,8
;        int     0x90          
;        invoke  Draw_Picture,edx,60,picfile,[WinID]
;
;        pusha
;        mov     eax,0x22
;        int     0x90
;        add     esi,delay
;        mov     [old_tick],esi
;        popa
;
;        inc     ax
;        cmp     ax,[cnt]
;        jne     no_repe_put
;        mov     [cnt],0
;        jmp     repe_put
;      no_repe_put:
;        inc     [cnt]
;      no_img:
;        ;;;;;;;;;;;;;;


        jmp     Wait_Event

delay           = 15
cnt dw 0
old_tick dd 0

Redraw:
;mov [cnt],0
        push    [Buttons]
        push    dword my_name
        push    [Default_XYSize]
        push    [Default_XY]        
        call    [Draw_StdWindow]
        mov     [WinID],eax

        invoke  Write_Text,15,0x16+10,1,4,"http://kreoton.com/",[WinID]

        push    dword 10b
        push    dword 11
        push    dword btext
        push    dword 100*65536+30
        push    dword 30*65536+60
        call    [Create_StdButton]

        push    dword 10b
        push    dword 12
        push    dword 30*65536+120
        call    [Create_CheckButton]
        

        mov     esi,PicFile
        mov     edi,picfile
        mov     eax,8
        int     0x90          
        invoke  Draw_Picture,150,60,picfile,[WinID]
        call    [End_of_redraw]
        ret

PicFile         db 'pic.gif',0
btext           db 'Cancel',0

Maximize:
        pusha
        push    [WinID]
        call    [Get_WinParams]
        mov     [Save_XY],esi
        mov     [Save_XYSize],edi
        
        call    [Get_XYSize]
        shl     esi,16
;        sub     di,10
        mov     si,di
        
        mov     [Buttons],default_buttons or 1000b
        mov     [Default_XY],0
        mov     [Default_XYSize],esi
        call    Redraw
        popa
        ret

Restore_:
        pusha
        mov     [Buttons],default_buttons
        mov     eax,[Save_XY]
        mov     [Default_XY],eax
        mov     eax,[Save_XYSize]
        mov     [Default_XYSize],eax
        call    Redraw
        popa
        ret

EventID_Redraw          = 1
EventID_Focus           = 2
EventID_LostFocus       = 3
EventID_Close           = 4
EventID_MouseEvent      = 5
EventID_Ctrl0           = 10
EventID_Ctrl1           = 11
EventID_Ctrl2           = 12
EventID_Ctrl3           = 13
EventID_Maximize        = 14
EventID_Restore         = 15
EventID_Kbd             = 20
EventID_IPC             = 50

; Reserved ctrl:
CtrlID_Moving           = 0xFF
CtrlID_CSize            = 0xFE

data import
;
; Import functions:
;

  library mx32,'mx32.dll'

  import mx32,\
         f1,'OneFunction',\
         VirtualAlloc,'VirtualAlloc',\
         VirtualProtect,'VirtualProtect',\
         VirtualFree,'VirtualFree',\
         CreateProcess,'CreateProcess',\
         ExitProcess,'ExitProcess',\
         CreateThread,'CreateThread',\
         ExitThread,'ExitThread',\
         TestKbdInput,'TestKbdInput',\
         PutChar,'PutChar',\
         PutChar2,'PutChar2',\
         PrintString,'PrintString',\
         Get_Position,'Get_Position',\
         Set_Position,'Set_Position',\
         Set_focus,'Set_focus',\
         Set_focusPID,'Set_focusPID',\
         Get_FileAddress,'Get_FileAddress',\
         Inkey,'Inkey',\
         SendMessage,'SendMessage',\
         ReceiveMessage,'ReceiveMessage',\
         WaitMessage,'WaitMessage',\
         GetPID,'GetPID',\
         DefineWindow,'DefineWindow',\
         DefineButton,'DefineButton',\
         Put_pixel,'Put_pixel',\
         Get_screen_param,'Get_screen_param',\
         Draw_BLine,'Draw_BLine',\
         Draw_Picture,'Draw_Picture',\
         Kill_Window,'Kill_Window',\
         Write_Text,'Write_Text',\
         WriteText,'WriteText',\
         Write_Hex,'Write_Hex',\
         Draw_StdWindow,'Draw_StdWindow',\
         StdHandler,'StdHandler',\
         Draw_hLine,'Draw_hLine',\
         Get_XYSize,'Get_XYSize',\
         Get_WinParams,'Get_WinParams',\
         End_of_redraw,'End_of_redraw',\
         Begin_xDraw,'Begin_xDraw',\
         Get_focus,'Get_focus',\
         Create_CheckButton,'Create_CheckButton',\
         Create_StdButton,'Create_StdButton'


 
end data

section '.rsrc' resource data readable

  ; resource directory

  directory RT_ICON,icons,\
            RT_GROUP_ICON,group_icons,\
            RT_VERSION,versions

  ; resource subdirectories

  resource icons,\
           1,LANG_NEUTRAL,icon_data

  resource group_icons,\
           17,LANG_NEUTRAL,main_icon

  resource versions,\
           1,LANG_NEUTRAL,version

  icon main_icon,icon_data,'..\include\mx.ico'

  versioninfo version,\
          VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
          'FileDescription','Example Application',\
          'FileVersion','1.0',\
          'OriginalFilename','HELLO.EXE',\
          'InternalName','Hello World',\
          'SpecialBuild',SpecialBuild,\
          'ProductName',ProductName,\
          'ProductVersion',ProductVersion,\
          'LegalCopyright',LegalCopyright,\
          'CompanyName',CompanyName,\
          'Comments',rsrcComments,\
          'LegalTrademarks',LegalTrademarks

;section '.data' data readable writeable
  Buttons               dd default_buttons
  Default_XY            dd 0
  Default_XYSize        dd 0
  Save_XY               dd 0
  Save_XYSize           dd 0
  WinID                 dd 0
                            
  my_name               db 'Example Application',0

hextmp          db '00000000',0
text            db 'http://www.sysbin.com - 2 year',0
text1           db 'Get focus',0
text2           db 'Lost focus',0

  picfile               rb 0x100000
MaxImg          rw 0
next_img        rw 0
  counterx              rd 1

section '.reloc' fixups data readable discardable
